﻿using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.Tests
{
	[TestFixture]
	public class UiTest : SerializationTestBase<Ui>
	{
		[Test]
		public void EmptyUiTest()
		{
			InitializeTestEntity("Simple/EmptyUi.xml");
		}

		[Test]
		public void IncludeTest()
		{
			InitializeTestEntity(("Simple/UiInclude.xml"));

			Assert.IsNotNull(TestEntity.Includes);
			Assert.AreEqual(2, TestEntity.Includes.Length);
			Assert.AreEqual("EmptyUi.xml", TestEntity.Includes[0].File);
			Assert.AreEqual("UiScript.xml", TestEntity.Includes[1].File);

			AssertNoUnknownElements(TestEntity.Includes);
		}

		[Test]
		public void ScriptTest()
		{
			InitializeTestEntity("Simple/UiScript.xml");

			Assert.IsNotNull(TestEntity.Scripts);
			Assert.AreEqual(2, TestEntity.Scripts.Length);
			Assert.AreEqual("UiScript.lua", TestEntity.Scripts[0].File);
			Assert.AreEqual("print(\"Hello world!\");", TestEntity.Scripts[1].ScriptBlock);

			AssertNoUnknownElements(TestEntity.Scripts);
		}

		[Test]
		public void FontTest()
		{
			InitializeTestEntity("Simple/UiFont.xml");

			Assert.IsNotNull(TestEntity.Fonts);
			Assert.AreEqual(2, TestEntity.Fonts.Count);

			// MasterFont
			Assert.AreEqual("MasterFont", TestEntity.Fonts[0].Name);
			Assert.AreEqual(true, TestEntity.Fonts[0].Virtual);
			Assert.IsNotNull(TestEntity.Fonts[0].Shadow);
			Assert.IsNotNull(TestEntity.Fonts[0].Shadow.Offset);

			// GameFontNormal
			Assert.AreEqual("GameFontNormal", TestEntity.Fonts[1].Name);
			Assert.AreEqual("MasterFont", TestEntity.Fonts[1].Inherits);
			Assert.IsNotNull(TestEntity.Fonts[1].Color);
			Assert.IsNotNull(TestEntity.Fonts[1].FontHeight);
			Assert.AreEqual(12, TestEntity.Fonts[1].FontHeight.Value);

			AssertNoUnknownElements(TestEntity.Fonts);
			AssertNoUnknownElements(TestEntity.Fonts[0].Shadow);
			AssertNoUnknownElements(TestEntity.Fonts[0].Shadow.Offset);
			AssertNoUnknownElements(TestEntity.Fonts[1].FontHeight);
		}

		/// <summary>
		/// Gets the entity to be tested from a <see cref="Ui"/> instance.
		/// </summary>
		/// <param name="ui">The ui instance.</param>
		/// <returns>
		/// An instance of the <typeparamref name="TSerializationObject"/> class.
		/// </returns>
		protected override Ui GetTestEntity(Ui ui)
		{
			return ui;
		}
	}
}